package com.kexio.user.dto;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * 登出请求DTO
 * 
 * 用户登出时提交的请求参数
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class LogoutRequest implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 访问令牌（可选，从Header中自动获取）
     */
    private String accessToken;
    
    /**
     * 刷新令牌（可选）
     */
    private String refreshToken;

    /**
     * 会话ID（优先用于精准终止会话；若缺失则通过JTI反查）
     */
    private String sessionId;
    
    /**
     * 租户ID（多租户场景）
     */
    private String tenantId;
    
    /**
     * 登出类型：manual-手动登出，timeout-超时登出，kickout-强制登出
     */
    private String logoutType = "manual";
    
    /**
     * 登出原因（可选）
     */
    private String logoutReason;
    
    /**
     * 是否登出所有设备
     */
    private Boolean logoutAllDevices = false;
    
    /**
     * 客户端设备信息
     */
    private String deviceInfo;
    
    /**
     * 客户端IP地址（由服务端自动获取，客户端无需传入）
     */
    private String clientIp;
    
    /**
     * User-Agent信息（由服务端自动获取，客户端无需传入）
     */
    private String userAgent;
    
    // ==================== 构造函数 ====================
    
    public LogoutRequest() {}
    
    public LogoutRequest(String logoutType) {
        this.logoutType = logoutType;
    }
    
    public LogoutRequest(String logoutType, String logoutReason) {
        this.logoutType = logoutType;
        this.logoutReason = logoutReason;
    }
    
    // ==================== 便捷方法 ====================
    
    /**
     * 判断是否为手动登出
     */
    public boolean isManualLogout() {
        return "manual".equals(this.logoutType);
    }
    
    /**
     * 判断是否为超时登出
     */
    public boolean isTimeoutLogout() {
        return "timeout".equals(this.logoutType);
    }
    
    /**
     * 判断是否为强制登出
     */
    public boolean isKickoutLogout() {
        return "kickout".equals(this.logoutType);
    }
    
    /**
     * 判断是否需要登出所有设备
     */
    public boolean needLogoutAllDevices() {
        return Boolean.TRUE.equals(logoutAllDevices);
    }
    
    /**
     * 判断是否为多租户请求
     */
    public boolean isMultiTenant() {
        return tenantId != null && !tenantId.trim().isEmpty();
    }
    
    /**
     * 判断是否有刷新令牌
     */
    public boolean hasRefreshToken() {
        return refreshToken != null && !refreshToken.trim().isEmpty();
    }
    
    // ==================== Getter/Setter ====================
    
    public String getAccessToken() {
        return accessToken;
    }
    
    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }
    
    public String getRefreshToken() {
        return refreshToken;
    }
    
    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }
    
    public String getTenantId() {
        return tenantId;
    }
    
    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }
    
    public String getLogoutType() {
        return logoutType;
    }
    
    public void setLogoutType(String logoutType) {
        this.logoutType = logoutType;
    }
    
    public String getLogoutReason() {
        return logoutReason;
    }
    
    public void setLogoutReason(String logoutReason) {
        this.logoutReason = logoutReason;
    }
    
    public Boolean getLogoutAllDevices() {
        return logoutAllDevices;
    }
    
    public void setLogoutAllDevices(Boolean logoutAllDevices) {
        this.logoutAllDevices = logoutAllDevices;
    }
    
    public String getDeviceInfo() {
        return deviceInfo;
    }
    
    public void setDeviceInfo(String deviceInfo) {
        this.deviceInfo = deviceInfo;
    }
    
    public String getClientIp() {
        return clientIp;
    }
    
    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }
    
    public String getUserAgent() {
        return userAgent;
    }
    
    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }
    
    @Override
    public String toString() {
        return "LogoutRequest{" +
                "accessToken='[PROTECTED]'" +
                ", refreshToken='[PROTECTED]'" +
                ", sessionId='" + sessionId + '\'' +
                ", tenantId='" + tenantId + '\'' +
                ", logoutType='" + logoutType + '\'' +
                ", logoutReason='" + logoutReason + '\'' +
                ", logoutAllDevices=" + logoutAllDevices +
                ", deviceInfo='" + deviceInfo + '\'' +
                ", clientIp='" + clientIp + '\'' +
                ", userAgent='" + userAgent + '\'' +
                '}';
    }
}
